/**
 * 获取位置
 */
function getLocation(){
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(showPosition,showError,{timeout: 5000});
    }else{
        layerMsg("无法使用定位,请手动打开浏览器的定位功能！",2);
    }
}
//点击允许 获取坐标值
function showPosition(position){
    if( position_denied == '' ){
        var _lat = position.coords.latitude;
        var _lng = position.coords.longitude;
        location = '/mobile/job?nearby=1&position_denied=1&_lng='+_lng+'&_lat='+_lat;
    }
}

/**
 * 显示错误信息
 * @param error
 */
function showError(error){
    if( position_denied == '' ){
        switch(error.code){
            case error.PERMISSION_DENIED:
                layerMsg("请在弹出窗口时点允许才能使用定位！",2);
                // 百度地图API功能
                var map = new BMap.Map("juli");
                var point = new BMap.Point(116.331398,39.897445);
                map.centerAndZoom(point,12);
                var geolocation = new BMap.Geolocation();
                geolocation.getCurrentPosition(function(r){
                    if(this.getStatus() == BMAP_STATUS_SUCCESS){
                        var mk = new BMap.Marker(r.point);
                        map.addOverlay(mk);
                        map.panTo(r.point);
                        location = '/mobile/job?nearby=1&position_denied=1&_lng='+r.point.lng+'&_lat='+r.point.lat;
                    }
                    else {
                        layerMsg("定位错误",2);
                    }
                },{enableHighAccuracy: true});
                break;
            case error.POSITION_UNAVAILABLE:
                layerMsg("无法使用定位,请手动打开浏览器的定位功能！",2);
                break;
            case error.TIMEOUT:
                layerMsg("定位超时！",2);
                break;
            case error.UNKNOWN_ERROR:
                layerMsg("定位错误!",2);
                break;
        }
    }
}